/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package towerz.game.entity.hut;

import javax.microedition.lcdui.Graphics;
import towerz.game.entity.Entity;
import towerz.system.Utilities;

/**
 *
 * @author LegACy
 */
public class Hut extends Entity {
	protected Hut() {
		//Super
		super();

		//Initialize
		m_TileX = 0;
		m_TileY	= 0;
		m_Data	= null;
	}

	public Hut(HutData data, int x, int y) {
		//Default
		this();

		//Save
		m_TileX = x;
		m_TileY = y;
		m_Data	= data;
	}

	public HutData getData() {
		return m_Data;
	}

	public HutData getUpgrade() {
		//
		return m_Upgrade;
	}

	public void applyUpgrade(HutData upgrade) {
		m_Upgrade = upgrade;
	}

	public void upgrade(HutData upgrade) {
		//Set as data
		m_Data		= upgrade;
		m_Upgrade	= null;
	}

	public void draw(Graphics g, int startX, int startY, int endX, int endY, int offsetX, int offsetY) {
		//Skip if no image
		if (m_Data.getImage() == null) return;

		//Ensure in drawing area
		if (m_TileX < startX)	return;
		if (m_TileY < startY)	return;
		if (m_TileX > endX)		return;

		//Calculate draw position
		int X = ((m_TileX - startX) * Utilities.TILE_WIDTH)  + offsetX + (Utilities.TILE_WIDTH / 2);
		int Y = ((m_TileY - startY) * Utilities.TILE_HEIGHT) + offsetY +  Utilities.TILE_HEIGHT;

		if (Y - m_Data.getImage().getHeight() > ((endY + 1) * Utilities.TILE_HEIGHT) + offsetY) return;

		//Draw
		g.drawImage(m_Upgrade == null ? m_Data.getImage() : m_Upgrade.getImage(), X, Y, Graphics.HCENTER | Graphics.BOTTOM);
	}

	//Members
	protected HutData m_Data;
	protected HutData m_Upgrade;
}
